package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
    private  CategoryService categoryService;
    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result<PageResult> page( CategoryPageQueryDTO dto){
       PageResult pageResult = categoryService.page(dto);
       return Result.success(pageResult);
    }
@ApiOperation("修改分类")
@PutMapping
    public Result update(@RequestBody CategoryDTO dto){
        categoryService.update(dto);
        return Result.success();
    }
    @ApiOperation("修改状态")
    @PostMapping("/status/{status}")
    public Result update(@PathVariable Integer status,Long id){
        categoryService.updateByStatus(status,id);
        return Result.success();
    }
    @ApiOperation("新增分类")
    @PostMapping
    public Result insert(@RequestBody CategoryDTO dto){
        categoryService.insert(dto);
        return Result.success();
    }
    @ApiOperation("删除分类")
    @DeleteMapping
    public Result<String> deleteById(Long id){
        categoryService.deleteById(id);
        return Result.success();
    }
    @ApiOperation("查询分类")
    @GetMapping("/list")
    public Result<List<Category>> select(Integer type){
        List<Category> categories = categoryService.select(type);
        return Result.success(categories);
    }



}
